package com.smart_campus.sys.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.sys.common.ActiveUser;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.common.ResultObj;
import com.smart_campus.sys.common.StringUtils;
import com.smart_campus.sys.domain.User;
import com.smart_campus.sys.domain.UserEstimate;
import com.smart_campus.sys.domain.UserInfo;
import com.smart_campus.sys.service.UserEstimateService;
import com.smart_campus.sys.service.UserInfoService;
import com.smart_campus.sys.service.impl.UserEstimateServiceImpl;
import com.smart_campus.sys.vo.EstimateVo;
import com.smart_campus.sys.vo.UserEstimateVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author:Omega
 * @Date:2020/6/18 15:08
 */

@Controller
@RequestMapping("UserEstimate")
public class UserEstimateController {
    @Autowired
    private UserEstimateService UEService;

    @Autowired
    UserInfoService userInfoService;

    /**留言
     * @param master
     * @param editorContent
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "Comment")
    public UserEstimate comment(String master,String editorContent,Integer pid){
        UserEstimate uE = new UserEstimate();
        uE.setPid(pid);
        uE.setComment(editorContent);
        uE.setMasterid(Integer.valueOf(master));
        //得到评论人的个人信息
        uE=UEService.insetUserEstimate(uE);
        return uE;
    }

    @ResponseBody
    @RequestMapping(value ="showComment" )
    public List<UserEstimateVo> showComment(Integer master,Integer page){
//        System.out.println(">>>>>>>>"+master);
        if (master==null||master==0){
            return null;
        }
        List<UserEstimateVo> UEVlist=UEService.selectUserEstimate(master,page);
        return UEVlist;
    }

    //查询所有方法
    @ResponseBody
    @RequestMapping(value = "sel")
    public DataGridView sel(EstimateVo estimateVo){
        return  UEService.selall(estimateVo);
    }

    //查询所有方法
    @ResponseBody
    @RequestMapping(value = "fuzzyquery")
    public DataGridView fuzzyquery(UserEstimateVo estimateVo){
        System.out.println("jll"+estimateVo.toString());
        return  UEService.fuzzyquery(estimateVo);
    }


    //删除方法
    @ResponseBody
    @RequestMapping("del")
    public ResultObj del(Integer id){
        try{
            UEService.deleteByPrimaryKey(id);
            return ResultObj.Estimate_DELETE_YES;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.Estimate_DELETE_No;
        }
    }

    //批量删除方法
    @ResponseBody
    @RequestMapping("delz")
    public ResultObj delz(Integer[] id){
        try{
            for (int i:id){
                UEService.deleteByPrimaryKey(i);
            }
            return ResultObj.Estimate_DELETE_YES;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.Estimate_DELETE_No;
        }
    }



}
